home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmiSoft / Util / Misc / Lottery2002.lha / Lottery2002 / Source / events.c < prev    next >
C/C++ Source or Header  |  2003-02-09  |  3KB  |  157 lines

  1. /* events.c */
  2.  
  3. #include "includes.h"
  4. #include "externals.h"
  5.  
  6. void events(struct MsgPort *AppPort, Object *object,
  7.             struct Gadget *gadgets[], struct Window *win)
  8. {
  9.     BOOL  done = FALSE;
  10.     ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  11.     ULONG result;
  12.     UWORD code;
  13.  
  14.     /* Obtain the window wait signal mask.*/
  15.     GetAttr(WINDOW_SigMask, object, &signal);
  16.  
  17.     /* Input Event Loop*/
  18.     while (!done)
  19.     {
  20.         wait = Wait( signal | app );
  21.  
  22.         while ((result = RA_HandleInput(object, &code)) != WMHI_LASTMSG)
  23.         {
  24.             switch (result & WMHI_CLASSMASK)
  25.             {
  26.                 case WMHI_CLOSEWINDOW:
  27.                     win  = NULL;
  28.                     done = TRUE;
  29.                 break;
  30.  
  31.                 case WMHI_GADGETUP:
  32.                     done = handlegads(win, gadgets, code, (result & WMHI_GADGETMASK));
  33.                 break;
  34.  
  35.                 case WMHI_GADGETHELP:
  36.                 {
  37.                     ULONG helpcode = (result & WMHI_GADGETMASK);
  38.  
  39.                     if((helpcode == 0) || (helpcode == 65535))
  40.                         SetWindowTitles(win, (UBYTE *)-1, g_scrtitle);
  41.                     else
  42.                         handlehelp(win, helpcode);
  43.                 }
  44.                 break;
  45.  
  46.                 case WMHI_MENUPICK:
  47.                     done = handlemenus(win, gadgets, object, (result & WMHI_MENUMASK));
  48.  
  49.                 break;
  50.  
  51.                 case WMHI_VANILLAKEY:
  52.                     done = handlegads(win, gadgets, code, (result & WMHI_KEYMASK));
  53.                 break;
  54.  
  55.                 case WMHI_ICONIFY:
  56.                     RA_Iconify(object);
  57.                     win = NULL;
  58.                 break;
  59.  
  60.                 case WMHI_UNICONIFY:
  61.                     win = (struct Window *) RA_OpenWindow(object);
  62.  
  63.                     if (win)
  64.                     {
  65.                         GetAttr(WINDOW_SigMask, object, &signal);
  66.                     }
  67.                     else
  68.                     {
  69.                         done = TRUE;    // could not re-open window, Quit Lottery2002
  70.                     }
  71.                 break;
  72.             }
  73.         }
  74.     }
  75. }
  76.  
  77. /* Handles Help events */
  78. void handlehelp(struct Window *win, ULONG helpcode)
  79. {
  80.     char *spkhlp = "Speak disabled, No narrator.device or translator.library =>V36.";
  81.  
  82.     if(spk_flag)
  83.         spkhlp = "Speak the Lottery numbers, Wed 1st then Sat.";
  84.     {
  85.         char *helptext[] = {NULL,
  86.                                  g_scrtitle,
  87.                          "Start generating random lottery numbers.",
  88.                          spkhlp,
  89.                          "Click here to Quit Lottery2002."};
  90.  
  91.         SetWindowTitles(win, (UBYTE *)-1, helptext[helpcode - 12]);
  92.     }
  93. }
  94.  
  95. /* Handles Menu events */
  96. BOOL handlemenus(struct Window *win, struct Gadget *gads[],
  97.                         Object *object,UWORD m_number)
  98. {
  99.     BOOL   done = FALSE;
  100.     UWORD  menunum, itemnum, subnum;
  101.     struct MenuItem *item;
  102.  
  103.     while((m_number != MENUNULL) && (!done))
  104.     {
  105.         item = ItemAddress(g_menustrip, m_number);
  106.         menunum = MENUNUM(m_number);
  107.         itemnum = ITEMNUM(m_number);
  108.         subnum  = SUBNUM(m_number);
  109.  
  110.         if(menunum == 0)
  111.         {
  112.             switch(itemnum)
  113.             {
  114.                 case 0: // START
  115.                     get_num(win, gads);
  116.                 break;
  117.  
  118.                 case 1: // SPEAK
  119.                     {
  120.                         putbusy(win);
  121.  
  122.                         if(speaknums(wednums, 0))
  123.                             speaknums(satnums, 1);
  124.  
  125.                         clearbusy(win);
  126.                     }
  127.                 break;
  128.  
  129.                 case 3: // ABOUT
  130.                     {
  131.                         char *abouttext[] = {
  132.                            "\nLottery2000 V2.1  (OS3.5/9).\n\n"
  133.                            "(c) T. Collier 2002. \n\n"
  134.                            "Written in 'C' Using Dice 3.2 & StormC Pro 3.\n\n"
  135.                            "Gadget Help is shown in the screen title bar.\n"};
  136.                         putbusy(win);
  137.                         requester("About Lottery 2002", *abouttext, g_okbutton);
  138.                         clearbusy(win);
  139.                     }
  140.                 break;
  141.  
  142.                 case 4: // ICONIFY
  143.                     RA_Iconify(object);
  144.                     win = NULL;
  145.                 break;
  146.  
  147.                 case 6: // QUIT
  148.                     done = TRUE;
  149.                 break;
  150.             }
  151.  
  152.         }
  153.         m_number = item->NextSelect;
  154.     }
  155.     return(done);
  156. }
  157.